﻿package net.jmp0.toast.entities.bases
{
	import punk.Acrobat;
	import punk.util.Input;
	/**
	 * ...
	 * @author Thodd
	 */
	public class GameButton extends Acrobat
	{
		protected var callback:Function;
		protected var mouseIsOverMe:Boolean = false;
		
		public function GameButton(x:int, y:int, callback:Function){
			this.x = x;
			this.y = y;
			this.callback = callback;
			this.depth = -302;
			FP.world.add(this);
		}
		
		public function destroy():void {
			FP.world.remove(this);
		}
		
		override public function update():void {
			
			mouseIsOverMe = mouseOver();
			
			if (Input.mousePressed) {
				if(mouseIsOverMe){
					callback(this);
				}
			}
			
		}
		
		protected function mouseOver():Boolean {
			if (Input.mouseX >= x && Input.mouseX <= x + sprite.imageW &&
				Input.mouseY >= y && Input.mouseY <= y + sprite.imageH)
			{
				return true;
			}else {
				return false;
			}
		}
		
	}

}